/**
 * 
 */
package org.dse.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * This class helps other classes to access the application context in Spring
 * framework.
 * 
 * Because this system is not a web application, the spring framework does
 * create an application context automatically. We have to create it by
 * ourselves.
 * 
 * This class provides only one method to get beans from the application
 * context.
 * 
 * @author zhangchen
 * 
 */
public class ApplicationContextUtil {

	private static final String CONTEXT_FILE = "applicationContext.xml";

	/**
	 * The application context containing all beans. Use
	 * ClassPathXmlApplicationContext to access the xml document in the class
	 * path.
	 */
	public static ApplicationContext context = new ClassPathXmlApplicationContext(
			CONTEXT_FILE);

	/**
	 * Get a specific bean from the application context. Only use the method the
	 * Spring provides. The return value is an Object, so you have to perform
	 * type cast.
	 * 
	 * @param beanName
	 *            the id configged in the xml document
	 * @return the bean identified by the beanName, please perform type cast
	 */
	public static Object getBean(String beanName) {
		return context.getBean(beanName);
	}
}
